package com.aruba.viewmodel;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private NumberViewModel numberViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        numberViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication())).get(NumberViewModel.class);

        textView = findViewById(R.id.textView);
        textView.setText(String.valueOf(numberViewModel.number));
    }

    public void addCount(View view) {
        numberViewModel.number++;
        textView.setText(String.valueOf(numberViewModel.number));
    }
}